home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / PCI Driver Development Kit / • Tools / Utility / DisplayNameRegistry 950412 / Src / AppleEventCore.h < prev    next >
Encoding:
Text File  |  1997-02-27  |  12.7 KB  |  422 lines  |  [TEXT/MPCC]

  1. /*                                    AppleEventCore.h                            */
  2. /*
  3.  * AppleEventCore.h
  4.  * Copyright © 1988-94 Apple Computer Inc. All rights reserved.
  5.  *
  6.  * Simple functions to integrate AppleEvents into "normal" applications. This
  7.  * library handles the four required AppleEvents (init, open, print, quit)
  8.  * and has a few routines to simplify access to event parameters.
  9.  *
  10.  * Usage:
  11.  *    
  12.  *    pascal OSErr                InitializeAppleEvents(
  13.  *            AEOpenAppHandlerFunc    aeOpenAppHandlerFunc,
  14.  *            AEDocumentHandlerFunc    aeOpenDocHandlerFunc,
  15.  *            AEDocumentHandlerFunc    aePrintDocHandlerFunc,
  16.  *            AEQuitAppHandlerFunc    aeQuitAppHandlerFunc,
  17.  *            AEDoScriptHandlerFunc    aeDoScriptHandlerFunc,
  18.  *            AEUnknownHandlerMsgFunc    aeUnknownHandlerMsgFunc,
  19.  *            long                    refCon
  20.  *        );
  21.  *
  22.  *        Call this as part of your application startup process (after initializing
  23.  *        the managers, but before calling WaitNextEvent). It returns noErr on
  24.  *        success, or some system error (gestaltUndefSelectorErr if AppleEvents are
  25.  *        not supported). DoHighLevelEvent will call one of the handler functions
  26.  *        when the appropriate event occurs. The table pointers let your application
  27.  *        install its own handler and coercion functions. The library installs
  28.  *        "ignore" functions for the AppleScript recording events. The library does
  29.  *        not install any coercion events. Pass NULL if you don't support one of
  30.  *        the functions (but do support OpenApp and Quit).
  31.  *
  32.  *        The refCon will be passed back to the handler functions.
  33.  *
  34.  *        If aeDoScriptHandlerFunc is provided, script AppleEvents ('misc', 'dosc')
  35.  *        will be passed to the handler with the key data ('----') stored in a
  36.  *        character string (null-terminated C-string).
  37.  *
  38.  *        If aeUnknownHandlerMsgFunc is not NULL, it will be called with a text
  39.  *        message if an unknown event is encounteres. The caller can display a
  40.  *        non-fatal error alert (don't forget to call AEInteractionOK first).
  41.  *
  42.  *        After InitializeAppleEvents returns noErr, call AEInstallEventHandlers
  43.  *        and/or AEInstallCoercionHandlers to install application-specific handlers. 
  44.  *
  45.  *        The document handlers should only return an error status if the entire
  46.  *        open/print handler should be terminated: errors that are unique to a
  47.  *        single file should not be returned to the handler.
  48.  *
  49.  *    pascal OSErr                AEInstallEventHandlers(
  50.  *            AEHandlerDefPtr            aeHandlerDefPtr,
  51.  *            long                    refCon
  52.  *        );
  53.  *
  54.  *        Install event handlers from a pre-compiled table. All handlers will have
  55.  *        a common refCon.
  56.  *
  57.  *    pascal OSErr                AEInstallCoercionHandlers(
  58.  *            AECoercionDefPtr        aeCoercionDefPtr,
  59.  *            long                    refCon
  60.  *        );
  61.  *
  62.  *        Install coercion handlers from a pre-compiled table. All handlers will
  63.  *        have a common refCon.
  64.  
  65.  *
  66.  *        To process events, add the following to your application event loop:
  67.  *            status = AEProcessAppleEvent(eventRecordPtr);
  68.  *        All the work is done by handler functions.
  69.  *
  70.  *    pascal OSErr                AEIgnore(
  71.  *            const AppleEvent        *theEvent,
  72.  *            AppleEvent                *theReply,
  73.  *            long                    refCon
  74.  *        );
  75.  *
  76.  *        This is for the convenience of application event handlers installation.
  77.  *
  78.  * The following are not directly used to handle AppleEvents.
  79.  *
  80.  *    pascal OSErr                AEHandlerSetup(
  81.  *            const AppleEvent        *theEvent,
  82.  *            AppleEvent                *theReply,
  83.  *            long                    refCon
  84.  *        );
  85.  *
  86.  *    All handlers should call this function at the start of processing. It stores
  87.  *    the parameters in a global area for debugging convenience, and initializes
  88.  *    some variables. Handlers should act as follows:
  89.  *
  90.  *            status = AEHandlerSetup(theEvent, theReply, refCon);
  91.  *            if (status == noErr) {
  92.  *                ... Get required parameters ...
  93.  *                status = AEGotRequiredParams(theEvent);
  94.  *                ... Get optional parameters ...
  95.  *            }
  96.  *            if (status == noErr) {
  97.  *                ... Process the event ...
  98.  *            }
  99.  *            gAECoreGlobals.currentEventIsAppleEvent = FALSE;
  100.  *            return (status);
  101.  *
  102.  *
  103.  *    pascal OSErr                AEMakeTargetAddress(
  104.  *            AETargetAddressType        aeTargetAddressType,
  105.  *            AEDesc                    *theAddress,
  106.  *            StringPtr                targetName
  107.  *        );
  108.  *
  109.  *        Create a descriptor to send AppleEvents. There are three target types:
  110.  *        kAETargetSelfCurrentProcess    This is the normal call for self-events as
  111.  *                                    would be used by scriptable applications.
  112.  *                                    The AppleEvent manager calls the event
  113.  *                                    handler directly. This is quite efficient.
  114.  *        kAETargetSelfUsingPSN        This send an event to the current application
  115.  *                                    through the event loop. It might be used
  116.  *                                    for debugging.
  117.  *        kAETargetOtherApplication    This calls the AppleEvent browser to select
  118.  *                                    a target application. It would be used by
  119.  *                                    client applications.
  120.  *        On return, targetName may be used for Alerts.
  121.  *
  122.  *    pascal OSErr                AEBrowseForTarget(
  123.  *            ConstStr255Param        dialogPrompt,
  124.  *            ConstStr255Param        listHeader,
  125.  *            PPCFilterUPP            filterProcUPP,
  126.  *            ConstStr255Param        locNBPType,                
  127.  *            AEDesc                    *theAddress,
  128.  *            StringPtr                targetName
  129.  *        );
  130.  *
  131.  *        Call the PPCBrowser and create a target descriptor. This is called by
  132.  *        AEMakeTargetAddress(kAETargetOtherApplication, ...).
  133.  *
  134.  *    pascal OSErr                AELocateTarget(
  135.  *            ConstStr255Param        machineName,
  136.  *            const StringPtr            *targetNameVector,
  137.  *            AEDesc                    *theAddress,
  138.  *            StringPtr                actualTargetName
  139.  *        );
  140.  *
  141.  *        Call IPCListPorts to find a named application on a named machine. This
  142.  *        might be used for client-server applications. Only the current zone
  143.  *        is searched. targetNameVector is a vector a possible application strings.
  144.  *
  145.  *
  146.  *        pascal OSErr            AEGotRequiredParams(
  147.  *            const AppleEvent        *theEvent
  148.  *        );
  149.  *
  150.  *        This fails if not all required parameters have been extracted. Call this
  151.  *        after retrieving all required parameters before actually processing the
  152.  *        event. This sets GLOBAL.currentAEStatus to noErr if it succeeds. If
  153.  *        required parameters remain, it returns errAEParamMissed.
  154.  *
  155.  *        pascal Boolean            AEInteractionOK(
  156.  *            AEIdleUPP                aeIdleUPP
  157.  *        );
  158.  *
  159.  *        This should be called before doing any user-interaction, such as alerts
  160.  *        or dialogs. It returns FALSE if interaction is blocked at this time.
  161.  *        The application should provide an idle function UPP. For example,
  162.  *
  163.  *        pascal Boolean
  164.  *        MyAEIdleProc(
  165.  *                const EventRecord        *theEventPtr,
  166.  *                long                    *sleepTime,
  167.  *                RgnHandle                *mouseRgn
  168.  *            )
  169.  *        {
  170.  *                if (theEventPtr->what == kHighLevelEvent)
  171.  *                    return (TRUE);
  172.  *                else {
  173.  *                    *sleepTime = MyProcessThisEvent(theEventPtr);
  174.  *                    return (FALSE);
  175.  *                }
  176.  *        }
  177.  *
  178.  * Access AppleEvent data -- these are needed to process private events.
  179.  * These functions return errAEDescNotFound if the parameter was missing.
  180.  *
  181.  *        OSErr                    AEGetShort(
  182.  *            const AppleEvent        *theEvent,
  183.  *            DescType                parameterKey,
  184.  *            short                    *result;
  185.  *        );
  186.  *        OSErr                    AEGetLong(
  187.  *            const AppleEvent        *theEvent,
  188.  *            DescType                parameterKey,
  189.  *            long                    *result
  190.  *        );
  191.  *        OSErr                    AEGetBoolean(
  192.  *            const AppleEvent        *theEvent,
  193.  *            DescType                parameterKey,
  194.  *            Boolean                    *result
  195.  *        );
  196.  *        OSErr                    AEGetChars(
  197.  *            const AppleEvent        *theEvent,
  198.  *            DescType                parameterKey,
  199.  *            CharsHandle                *result
  200.  *        );
  201.  *        OSErr                    AEGetString(
  202.  *            const AppleEvent        *theEvent,
  203.  *            DescType                parameterKey,
  204.  *            StringPtr                result
  205.  *        );
  206.  *        OSErr                    AEPutShort(
  207.  *            AppleEvent                *theReply,
  208.  *            DescType                parameterKey,
  209.  *            short                    value
  210.  *        );
  211.  *        void                    AEPutLong(
  212.  *            AppleEvent                *theReply,
  213.  *            DescType                parameterKey,
  214.  *            long                    value
  215.  *        );
  216.  *        OSErr                    AEPutBoolean(
  217.  *            AppleEvent                *theReply,
  218.  *            DescType                parameterKey,
  219.  *            Boolean                    value
  220.  *        );
  221.  *        OSErr                    AEPutStringHandle(
  222.  *            AppleEvent                *theReply,
  223.  *            DescType                parameterKey,
  224.  *            const StringHandle        value
  225.  *        );
  226.  *        OSErr                    AEPutCharsHandle(
  227.  *            AppleEvent                *theReply,
  228.  *            DescType                parameterKey,
  229.  *            const CharsHandle        value
  230.  *        );
  231.  *        OSErr                    AEPutString(
  232.  *            AppleEvent                *theReply,
  233.  *            DescType                parameterKey,
  234.  *            constStr255Param        value
  235.  *        );
  236.  */
  237.  
  238. #ifndef __AppleEventCore__
  239. #define __AppleEventCore__
  240.  
  241. #include <Types.h>
  242. #include <TextEdit.h>
  243. #include <AppleEvents.h>
  244. #include <Gestalt.h>
  245.  
  246. /*
  247.  * Define a table used to install event handlers.
  248.  */
  249. typedef struct AEHandlerDefRec {
  250.     AEEventClass            eventClass;
  251.     AEEventID                eventID;
  252.     AEEventHandlerProcPtr    procPtr;
  253. } AEHandlerDefRec, *AEHandlerDefPtr;
  254.  
  255. /*
  256.  * Define a table used to install coercion handlers - we don't have any.
  257.  */
  258. typedef struct AECoercionDefRec{
  259.     DescType                fromType;
  260.     DescType                toType;
  261.     AECoercePtrProcPtr        procPtr;
  262. } AECoercionDefRec, *AECoercionDefPtr;
  263.  
  264. /*
  265.  * These are application-provided functions: the application must provide open
  266.  * and quit functions. DoHighLevelEvent will return an error to the AppleEvent
  267.  * Manager if a function is missing, or if the handler returns an error.
  268.  */
  269. typedef pascal OSErr    (*AEOpenAppHandlerFunc)(    /* Open App event handler    */
  270.         long                    refCon                /* Event refCon                */
  271.     );
  272. typedef pascal OSErr    (*AEDocumentHandlerFunc)(    /* Open or Print handler     */
  273.         const FSSpecPtr            fsSpecPtr,
  274.         long                    refCon                /* Event refCon                */
  275.     );
  276. typedef pascal OSErr    (*AEQuitAppHandlerFunc)(    /* Quit App event handler    */
  277.         long                    refCon                /* Event refCon                */
  278.     );
  279. typedef pascal OSErr    (*AEDoScriptHandlerFunc)(    /* 'misc' 'dosc'            */
  280.         Ptr                        scriptPtr,            /* Script text                */
  281.         Size                    scriptPtrLength,    /* Script text length        */
  282.         AppleEvent                *replyEvent,        /* What to tell the caller    */
  283.         long                    refCon                /* refCon from the event    */
  284.     );
  285. typedef pascal void        (*AEUnknownHandlerMsgFunc)(    /* Called on unknown events    */
  286.         ConstStr255Param        messageText
  287.     );
  288. pascal OSErr                InitializeAppleEvents(
  289.         AEOpenAppHandlerFunc    aeOpenAppHandlerFunc,
  290.         AEDocumentHandlerFunc    aeOpenDocHandlerFunc,
  291.         AEDocumentHandlerFunc    aePrintDocHandlerFunc,
  292.         AEQuitAppHandlerFunc    aeQuitAppHandlerFunc,
  293.         AEDoScriptHandlerFunc    aeDoScriptHandlerFunc,
  294.         AEUnknownHandlerMsgFunc    aeUnknownHandlerMsgFunc,
  295.         long                    refCon
  296.     );
  297. pascal OSErr                AEInstallEventHandlers(
  298.         AEHandlerDefPtr            aeHandlerDefPtr,
  299.         long                    refCon
  300.     );
  301. pascal OSErr                AEInstallCoercionHandlers(
  302.         AECoercionDefPtr        aeCoercionDefPtr,
  303.         long                    refCon
  304.     );
  305. pascal OSErr                AEIgnore(
  306.         const AppleEvent        *theEvent,
  307.         AppleEvent                *theReply,
  308.         long                    refCon
  309.     );
  310. pascal Boolean                AEInteractionOK(
  311.         AEIdleUPP                aeIdleUPP
  312.     );
  313. pascal OSErr                AEHandlerSetup(
  314.         const AppleEvent        *theEvent,
  315.         AppleEvent                *theReply,
  316.         long                    refCon
  317.     );
  318. pascal OSErr                AEGotRequiredParams(
  319.         const AppleEvent        *theEvent
  320.     );
  321.  
  322. typedef enum {
  323.     kAETargetSelfCurrentProcess = 0,
  324.     kAETargetSelfUsingPSN,
  325.     kAETargetOtherApplication
  326. } AETargetAddressType;
  327.  
  328. pascal OSErr                AEMakeTargetAddress(
  329.         AETargetAddressType        aeTargetAddressType,
  330.         AEDesc                    *theAddress,
  331.         StringPtr                targetName
  332.     );
  333. pascal OSErr                AEBrowseForTarget(
  334.         ConstStr255Param        dialogPrompt,
  335.         ConstStr255Param        listHeader,
  336.         PPCFilterUPP            filterProcUPP,
  337.         ConstStr255Param        locNBPType,                
  338.         AEDesc                    *theAddress,
  339.         StringPtr                targetName
  340.     );
  341. pascal OSErr                AELocateTarget(
  342.         ConstStr255Param        machineName,
  343.         const StringPtr            *targetNameVector,
  344.         AEDesc                    *theAddress,
  345.         StringPtr                actualTargetName
  346.     );
  347. pascal OSErr                AEGetShort(
  348.         const AppleEvent        *theEvent,
  349.         DescType                parameterKey,
  350.         short                    *result
  351.     );
  352. pascal OSErr                AEGetLong(
  353.         const AppleEvent        *theEvent,
  354.         DescType                parameterKey,
  355.         long                    *result
  356.     );
  357. pascal OSErr                AEGetBoolean(
  358.         const AppleEvent        *theEvent,
  359.         DescType                parameterKey,
  360.         Boolean                    *result
  361.     );
  362. pascal OSErr                AEGetChars(
  363.         const AppleEvent        *theEvent,
  364.         DescType                parameterKey,
  365.         CharsHandle                *result
  366.     );
  367. pascal OSErr                AEGetString(
  368.         const AppleEvent        *theEvent,
  369.         DescType                parameterKey,
  370.         StringPtr                result
  371.     );
  372. pascal OSErr                AEPutShort(
  373.         AppleEvent                *theReply,
  374.         DescType                parameterKey,
  375.         short                    value
  376.     );
  377. pascal OSErr                AEPutLong(
  378.         AppleEvent                *theReply,
  379.         DescType                parameterKey,
  380.         long                    value
  381.     );
  382. pascal OSErr                AEPutBoolean(
  383.         AppleEvent                *theReply,
  384.         DescType                parameterKey,
  385.         Boolean                    value
  386.     );
  387. pascal OSErr                AEPutStringHandle(
  388.         AppleEvent                *theReply,
  389.         DescType                parameterKey,
  390.         const StringHandle        value
  391.     );
  392. pascal OSErr                AEPutCharsHandle(
  393.         AppleEvent                *theReply,
  394.         DescType                parameterKey,
  395.         const CharsHandle        value
  396.     );
  397. pascal OSErr                AEPutString(
  398.         AppleEvent                *theReply,
  399.         DescType                parameterKey,
  400.         ConstStr255Param        value
  401.     );
  402.  
  403. /*
  404.  * These globals are defined by the AppleEvent library. They are globalized
  405.  * primarly for debugging convenience. The values in AECoreGlobals are only
  406.  * valid during AppleEvent processing.
  407.  */
  408. typedef struct {
  409.     const AppleEvent        *currentAEEvent;
  410.     AppleEvent                *currentAEReply;
  411.     OSErr                    currentAEStatus;
  412.     DescType                currentAEEventClass;
  413.     DescType                currentAEEventID;
  414.     long                    currentAEIntractionLevel;
  415.     Boolean                    currentEventIsAppleEvent;
  416.     long                    currentAERefCon;
  417. } AECoreGlobals, *AECoreGlobalsPtr;
  418.  
  419. extern AECoreGlobals        gAECoreGlobals;
  420. extern Boolean                gHasAppleEvents;            /* TRUE if supported    */
  421.  
  422. #endif /* __AppleEventCore__ */